//Copyright (c) 2010 Jimmy Merari - jim.merari@gmail.com

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;


namespace Cinovasi.Scriptagility
{
    [Serializable]
    public class ScriptInfo
    {
        public enum EPlacement
        {
            Disabled = 0,
            Head,
            Upper,
            InPlace,
            Lower,
            External
        };

        private int m_ScriptId;
        private int m_ModuleId;
        private string m_ScriptName;
        private EPlacement m_Placement;
        private string m_Script;
        private bool m_EnableTokenReplace;
        private string m_ContentType;
        private int m_ScriptOrder;


        public int ScriptId { get { return m_ScriptId; } set { m_ScriptId = value; } }
        public int ModuleId { get { return m_ModuleId; } set { m_ModuleId = value; } }
        public string ScriptName { get { return m_ScriptName; } set { m_ScriptName = value; } }
        public EPlacement Placement { get { return m_Placement; } set { m_Placement = value; } }
        public int PlacementInt { get { return (int)m_Placement; } set { m_Placement = (EPlacement)value; } }
        public string Script { get { return m_Script; } set { m_Script = value; } }
        public bool EnableTokenReplace { get { return m_EnableTokenReplace; } set { m_EnableTokenReplace = value; } }
        public string ContentType { get { return m_ContentType; } set { m_ContentType = value; } }
        public int ScriptOrder { get { return m_ScriptOrder; } set { m_ScriptOrder = value; } }

        public ScriptInfo()
        {
            m_ScriptName = "";
            m_Script = "";
            m_ContentType = "";
        }

        public int SaveScript()
        {
            return DataProvider.Instance().SaveScript(ScriptId, ModuleId, ScriptName,
                (int)Placement, Script, EnableTokenReplace, ContentType, ScriptOrder);
        }

        public static ArrayList GetScriptByModuleId(int moduleId)
        {
            return CBO.FillCollection(DataProvider.Instance().GetScriptByModuleId(moduleId), typeof(ScriptInfo));
        }

        public static ArrayList GetExternalScriptByModuleId(int moduleId)
        {
            return CBO.FillCollection(DataProvider.Instance().GetExternalScriptByModuleId(moduleId), typeof(ScriptInfo));
        }

        public static ScriptInfo GetExternalScriptByName(int moduleId, string name)
        {
            return (ScriptInfo)CBO.FillObject(DataProvider.Instance().GetExternalScriptByName(moduleId, name), typeof(ScriptInfo));
        }

        public static ScriptInfo GetScriptById(int scriptId)
        {
            return (ScriptInfo)CBO.FillObject(DataProvider.Instance().GetScriptById(scriptId), typeof(ScriptInfo));
        }

        public static void DeleteScript(int scriptId)
        {
            DataProvider.Instance().DeleteScript(scriptId);
        }
    }
}
